<?php

/**
 * 
 * 
 *
 */
class Quad_Iterable implements ArrayAccess, Iterator, Countable {
 
	protected $_array;
	
  public function __construct($array = array()) {
    $this->_array = $array;
  }
  
  // ArrayAccess Interface Functions
  public function offsetExists($offset) {
    return isset($this->_array[$offset]);
  }

  public function offsetGet($offset) {
    return $this->_array[$offset];
  }
 
  public function offsetSet($offset, $value) {
  	$this->_array[$offset] = $value;
  }
 
  public function offsetUnset($offset) {
  	unset($this->_array[$offset]);
  }

  // Countable Interface Functions
  public function count() {
    return count($this->_array);
  }
 
  // Iterator Interface Functions
  public function current() {
    return current($this->_array);
  }
 
  public function key() {
    return key($this->_array);
  }
 
  public function next() {
    return next($this->_array);
  }
 
  public function rewind() {
    return reset($this->_array);
  }
 
  public function valid() {
    return (key($this->_array) !== null);
  }
 
  public function getIterator() {
    return $this;
  }
  
  // other helpful functions
  public function clear() {
  	$this->_array = array();
  	return $this;
  }

  public function toArray() {
  	return $this->_array;
  }
  
}